<script type="text/javascript">
	Yutil.useLoadingMessage();
	Yutil.en.enhance();
</script>
<%

	String entId = request.getParameter("enterpriseId");
	//System.out.println("entId = " + entId);
	List enterprises = new ArrayList();
	List tmp;
	if (("-1").equals(entId)) {
		tmp = EnterpriseService.$.getAllEnterprises();
		for (Iterator itr = tmp.iterator(); itr.hasNext();) {
			enterprises.add(itr.next());
		}
	} else {
		Enterprise ent = EnterpriseService.$.getEnterpriseById(Integer
				.parseInt(entId));
		enterprises.add(ent);
	}
	UIutil $ = UIutil.$;
	
	
		//session id 
		//String userid = (String) session.getValue("user");
		//get all enterprises he owned
		//List enterpriseList = EnterpriseService.$.getAllEnterprises();
		//if business manager select from manage
		//if business operator select from own
		//if(null == enterpriseList) 
		//	enterpriseList = new ArrayList();
 %>
<div style="height: 6%">
	<table align='left'>
				<tr>
						<td>
							<input class='button' type="button" value="工资服务" onclick="if(theSameRate()) {	service();	}">
				</tr>
		</table>
</div>
<p></p>
<fieldset>
		<legend>企业列表</legend>
		<table align="left"  border="1px" class="grid">
				<thead>
					<tr>
						<th style="width:7%">选择</th>
						<th style="width:7%">企业编号</th>
						<th style="width:7%">企业名称</th>
						<th style="width:7%">企业代表编号</th>
						<th style="width:7%">企业代表</th>
						<th style="width:7%">企业创建日期</th>
						<th style="width:7%">企业代表电话</th>
						<th style="width:7%">联系电话</th>
						<th style="width:7%">注册资金</th>
						<th style="width:7%">所属类别</th>
						<th style="width:7%">所属行业</th>
						<th style="width:7%">企业描述</th>
						<th style="width:7%">部门代码</th>
					</tr>
				</thead>
				<tbody id="enterprises" style="width:100%">
				<%
					for(int i = 0 ; i < enterprises.size(); i++) {
						Enterprise enterprise = (Enterprise) enterprises.get(i);
						List employeeList = new ArrayList(); 
						employeeList = EnterpriseService.$.getAllEmployees(enterprise); 
				%>
							<tr style="width:100%">
								<td colspan="13" style="width:100%">
									<ul class="tree" style="width:100%">
										<li style="width:100%">	
											<span>
												<table style="width:100%" border="1px">
													<tr>
														<td style="width:7%"><input type="checkbox" id="selAll" value="<%= enterprise.getEnterpriseId()%>" onclick="selectAll(this)"/></td>
														<td style="width:7%">C<%= enterprise.getEnterpriseId()%></td>
														<td style="width:7%"><a href="javascript:;" onclick="toEmployeeList(this)" value="<%= enterprise.getEnterpriseId()%>"><%=enterprise.getName()%></a></td>
														<td style="width:7%"><%= enterprise.getRepresentativeId()%></td>
														<td style="width:7%"><%= enterprise.getRepresentative()%></td>
														<td style="width:7%"><%= enterprise.getCreatedate()%></td>
														<td style="width:7%"><%= enterprise.getRepresentativePhone()%></td>
														<td style="width:7%"><%= enterprise.getPhone()%></td>
														<td style="width:7%"><%= enterprise.getCapital()%></td>
														<td style="width:7%"><%= enterprise.getCategory()%></td>
														<td style="width:7%"><%= enterprise.getIndustry()%></td>
														<td style="width:7%"><%= enterprise.getDescription()%></td>
														<td style="width:7%"><%= enterprise.getOrgdeptcode()%></td>
													</tr>
												</table>
											</span>	
											<ul style="display:none">
											<%
												for(int j = 0; j < employeeList.size(); j++) {
													Employee e = (Employee) employeeList.get(j);	 
											%>
												<li>
													<span>
														<table border="1px" style="width:100%">
															<tr>
																<th></th>
																<th>人才编号</th>
																<th>人才名称</th>
															</tr>
															<tr></tr>
															<tr>
																<td>
																	<input type="checkbox" name="checkbox" enterprise="<%= enterprise.getEnterpriseId()%>" value="<%= "E" + e.getEmployeeId()%>" onclick="cascadeAll(this)"/>
																</td>
																<td>E<%= e.getEmployeeId()%></td>
																<td>
																	<a href="javascript:;" onclick="toService(this)" value="<%= "E" + e.getEmployeeId()%>"><%= e.getName()%></a>
																</td>
															</tr>
														</table>
													</span>
												</li>
											<%	
												}
											%>
											</ul>
										</li>
									</ul>
								</td>
							</tr>
							<tr></tr>
				<%
						}  
				%>
				</tbody>
		</table>
</fieldset>

<script type="text/javascript">
	cascadeAll = function(oElem) {
		var checked = oElem.checked;
		if(!checked) {
				$('selAll').checked = checked;
		} 
	}
	
	selectAll = function(oElem) {
		var checked = oElem.checked;
		var enterprise = oElem.getAttribute('value');
		var checkboxes = document.getElementsByName("checkbox");
		for(var i=0;i<checkboxes.length;i++) {
			var checkb = checkboxes[i];
			if(enterprise == checkb.getAttribute('enterprise'))
				checkb.checked = checked;
		}
	}
	
	theSameRate = function() {
		//here if the user select two or more different enterprises to update batchly, then we need to check all the rate first
		return true;
	}
	
	service = function() {
		var url = "f_insuranceAndHousingfund_calculate.jsp";
		var checkboxes = [];
		var arrays = jQuery.find("input[@name='checkbox']");
		for(var i=0;i<arrays.length;i++) {
			var checkbox = arrays[i];
			if(checkbox.checked) {
				checkboxes.push(checkbox.value);
			}
		}
		
		//check the number
		if(checkboxes.length <= 0) {
			alert("Please select at least one employee to calculate.");
			return;
		}
		
		//compose the employeeid array to a string
		var pars = "employeeids=";
		for(var i=0;i<checkboxes.length;i++) {
			if(i < checkboxes.length - 1) {
				pars += checkboxes[i] + ";"
			} else {
				pars += checkboxes[i];
			}
		}
		var myAjax = new Ajax.Updater('right',url,{method:'get',parameters:pars,evalScripts: true});
	}
</script>
<!-- No need, It is only for demo feature "tab" from jian.
	<%=  JspWidget.$.actionLink("企业1","la_employee_main.jsp", null)%>
	<br/>
 -->
	<script type="text/javascript">
			toEmployee = function(oElem) {
					var aLink = oElem;
					var url = 'la_employee_list.jsp';
					var pars = "employeeid="+ aLink.getAttribute('value');
					var myAjax = new Ajax.Updater('right',url,{method:'get', parameters: pars,  evalScripts: true});
			}
			
			toEmployeeList = function(toEmployeeListLink) {
					var aLink = toEmployeeListLink;
					var url = 'la_employee_list.jsp';
					var pars = "enterpriseId="+ aLink.getAttribute('value');
					var myAjax = new Ajax.Updater('right',url,{method:'get', parameters: pars,  evalScripts: true});
			}
			
			toService = function(oElem) {
				var aLink = oElem;
				var url = 'la_service_list.jsp';
				var pars = "thisemployeeid="+ aLink.getAttribute('value');
				var myAjax = new Ajax.Updater('right',url,{method:'get', parameters: pars,  evalScripts: true});
			}
	</script>

<!-- 
<img src="images/process.bmp"></img>
 -->
<%@ page import="com.esms.struts.service.JspWidget" %> 
<%@ page import="java.util.*" %>
<%@ page import="com.esms.bean.Enterprise" %>
<%@ page import="com.esms.bean.Employee" %>
<%@ page import="com.esms.struts.service.*" %>
<%@ page language="java" contentType="text/html; charset=utf-8" %>